package org.gwu.seuss.server.command;

import org.gwu.seuss.communication.domain.UserTO;
import org.gwu.seuss.communication.request.Actions;
import org.gwu.seuss.communication.request.ClientRequest;
import org.gwu.seuss.communication.request.ServerResponse;
import org.springframework.util.Assert;

public class RemoveUserCommand extends UserCommandBase implements Command {

	public RemoveUserCommand(ClientRequest req) {
		super(req);
	}

	@Override
	public ServerResponse execute() throws Exception {
		String username = req.getUsername();
		String password = req.getPassword();
		UserTO removeUser = req.getUser();

		Assert.hasText(username, "Username is not provided.");
		Assert.hasText(password, "Password is not provided.");
		Assert.notNull(removeUser, "User to remove is not provided");

		userService.actionAllowed(username, Actions.REMOVE_USER);
		log.info("User " + username + " requested to remove "
				+ removeUser.getUsername());

		int result = userService.removeUser(removeUser.getUsername());

		return getServerResponse(result, "User " + removeUser.getUsername()
				+ " removed.");
	}
}